package com.qqletter.utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.widget.Toast;

import com.qqletter.R;
import com.qqletter.common.Constants;

/**
 * @author Devin.Hu
 * @date 2011-8-24
 * @version V1.0
 * @description 辅助类
 */
public class AndroidUtils {

	/**
	 * 弹出Toast提示
	 * 
	 * @param context
	 * @param text
	 */
	public static void Toast(Context context,String text){
		Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
	}
	
	/**
	 * 弹出Dialog提示框
	 * 
	 * @param context
	 * @param msgId
	 */
	public static ProgressDialog showDialog(Context context){
		ProgressDialog dialog = ProgressDialog.show(context, "", context.getString(R.string.common_doing), true);
		dialog.setCancelable(true);
		return dialog;
	}
	
	/**
	 * 分享功能
	 * @param activity
	 */
	public static void sharePaiPai(String txt , Activity activity){
		Intent intent=new Intent(Intent.ACTION_SEND);  
		intent.setType("text/plain");  
		intent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.common_share_title));  
		intent.putExtra(Intent.EXTRA_TEXT, txt);  
		activity.startActivity(Intent.createChooser(intent, activity.getTitle()));  
	}
	
	/**
	 * 得到系统级别的缓存对象
	 * @param context
	 * @return
	 */
	public static SharedPreferences getSysShare(Context context){
		return context.getSharedPreferences(Constants.CACHE_SYS_MAP, Context.MODE_PRIVATE);
	}
	
	/**
	 * 添加系统缓存信息
	 * 
	 * @param context
	 * @param key
	 * @param value
	 */
	public static void addSysMap(Context context , String key , String value){
		Editor sysEdit =  getSysShare(context).edit();
		sysEdit.putString(key, value);
		sysEdit.commit();
	}
	
	/**
	 * 用户反馈发送邮件
	 * 
	 * @param context
	 * @param message
	 */
	public static void sendEmail(Context context, String feedEmail ,String message){
		Intent email = new Intent(Intent.ACTION_SEND);
		email.setType("plain/text");
		String[] emailReciver = new String[]{feedEmail};
		//设置邮件默认地址
		email.putExtra(Intent.EXTRA_EMAIL, emailReciver);
		//设置邮件默认标题
		email.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.common_email_subject));
		//设置要默认发送的内容
		email.putExtra(Intent.EXTRA_TEXT, message);
		//调用系统的邮件系统
		context.startActivity(Intent.createChooser(email, context.getString(R.string.common_email_tips)));
	}
	
	/**
	 * 判断网络类型
	 * @return
	 */
	public static boolean isWap() {
		String proxyHost = android.net.Proxy.getDefaultHost();
		if (proxyHost != null) {
			return true;
		} else {
			return false;
		}
	}
}
